home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Base / sa / succ_strm < prev   
Text File  |  1996-07-13  |  2KB  |  56 lines

  1. ---------------------------> Sather 1.1 source file <--------------------------
  2. -- Successor stream
  3. -- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>
  4. -- Copyright (C) 1995, International Computer Science Institute
  5. -- $Id: succ_stream.sa,v 1.1 1996/07/13 06:48:51 gomes Exp $
  6. --
  7. -- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
  8. -- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
  9. -- LICENSE contained in the file: Sather/Doc/License of the
  10. -- Sather distribution. The license is also available from ICSI,
  11. -- 1947 Center St., Suite 600, Berkeley CA 94704, USA.
  12. -------------------------------------------------------------------
  13. abstract class $SUCC_STREAM{NTP} is
  14.    -- An abstraction that specifies a generator of successive 
  15.    -- unique values of type NTP
  16.    
  17.    next: NTP;
  18.    -- Return the next unique value
  19.    
  20. end;
  21. -------------------------------------------------------------------
  22. class INT_STREAM < $SUCC_STREAM{INT} is
  23.    -- Yield a stream of successive integers
  24.  
  25.    private attr val: INT;
  26.    
  27.    create(start_val: INT): SAME is
  28.       -- Return a new integer stream whose next yielded
  29.       -- value will be "start_val"
  30.       res ::= new;
  31.       res.val := start_val;
  32.       return res;
  33.    end;
  34.    
  35.    next: INT is
  36.       -- Yield the next integer in this stream
  37.       -- Wrap around is not permitted in this kind of integer stream
  38.       res ::= val;
  39.       assert val /= INT::maxint;
  40.       val := val+1;
  41.       return res;
  42.    end;
  43.    
  44.    
  45.    next!: INT is
  46.       -- Keep yielding successive integers. 
  47.       -- Will quit at maxint - 1
  48.       if val = INT::maxint then quit end;
  49.       yield next;
  50.    end;
  51.    
  52. end;
  53. -------------------------------------------------------------------
  54.  
  55.  
  56.